const connection = require("../app/database");

class CollectService {
  async getListByUserId(userId) {
    const statement = `SELECT list_id as listId, collect_time AS collectionTime FROM user_collected WHERE user_id = ?;`;
    const [res, fields] = await connection.execute(statement, [userId]);
    return res;
  }
  async addUserCollection(listId, userId) {
    const statement = `INSERT INTO user_collected (user_id, list_id) VALUES (?, ?);`;
    const [res, fields] = await connection.execute(statement, [userId, listId]);
    return res;
  }
  async deleteUserCollection(listId, userId) {
    const statement = `DELETE FROM user_collected WHERE user_id = ? AND list_id = ?;`;
    const [res, fields] = await connection.execute(statement, [userId, listId]);
    return res;
  }
  async checkUserCollected(listId, userId) {
    const statement = `SELECT list_id as listId, collect_time AS collectionTime FROM user_collected WHERE user_id = ? AND list_id = ?;`
    const [res, fields] = await connection.execute(statement, [userId, listId]);
    return res
  }
}

module.exports = new CollectService();
